#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>

using namespace std;

vector<vector<int>> ret;
vector<int> path;
int aim = 0;

void dfs(vector<int> candidates, int pos, int sum)
{
    if (sum >= aim) {
        if (sum == aim)
            ret.push_back(path);

        return;
    }

    for (int i = pos ; i < candidates.size(); ++i)
    {
        path.push_back(candidates[i]);
        dfs(candidates, i , sum + candidates[i]);
        path.pop_back();
    }
}

vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
    aim = target;
    dfs(candidates, 0, 0);

    return ret;
}

int main()
{
    vector<int> num = { 2,3,5 };
    combinationSum(num, 8);
	return 0;
}